package com.samehope.ar.controller;


import com.samehope.ar.common.CommonResult;
import com.samehope.ar.dto.*;
import com.samehope.ar.entity.PatrolTaskPlan;
import com.samehope.ar.service.IPatrolTaskPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 巡检计划任务 前端控制器
 * </p>
 *
 * @author Zhang Luo
 * @since 2019-12-23
 */
@RestController
@RequestMapping("/patrolTaskPlan")
public class PatrolTaskPlanController {

    @Autowired
    private IPatrolTaskPlanService patrolTaskPlanService;

    @GetMapping("/pageList")
    public CommonResult pageList(@Valid PaginationParam paginationParam, PatrolTaskPlanQueryParam param){
        return CommonResult.success(patrolTaskPlanService.findByParam(paginationParam, param));
    }

    @PreAuthorize("hasRole('ROLE_PROJECT')")
    @PostMapping("/add")
    public CommonResult add(@RequestBody @Valid PatrolTaskPlanAddParam param){
        patrolTaskPlanService.add(param);
        return CommonResult.success(null);
    }

    @PreAuthorize("hasRole('ROLE_PROJECT')")
    @PutMapping("/update")
    public CommonResult update(@RequestBody @Valid PatrolTaskPlanUpdateParam param){
        patrolTaskPlanService.update(param);
        return CommonResult.success(null);
    }

    @PreAuthorize("hasRole('ROLE_PROJECT')")
    @DeleteMapping("/del/{planId}")
    public CommonResult del(@PathVariable Long planId){
        patrolTaskPlanService.del(planId);
        return CommonResult.success(null);
    }

    @GetMapping("/detail/{planId}")
    public CommonResult detail(@PathVariable("planId") Long planId){
        return CommonResult.success(patrolTaskPlanService.detail(planId));
    }
}
